//
//  SEGServerManager.m
//  Commom
//
//  Created by 山刘 on 2018/10/30.
//  Copyright © 2018年 山刘. All rights reserved.
//

#import "SEGServerManager.h"
#import "MJEncryptString.h"
#import "MJEncryptStringData.h"


#pragma mark - 请求接口版本号
NSString * const UserDefaultsClientVersionCodeTypeKey = @"VersionCodeTypeKey";//请求接口版本号

#pragma mark - 客户端类型
NSString * const UserDefaultsClientSourceTypeKey = @"ClientSourceTypeKey";//客户端类型

#pragma mark - 一个app使用多个服务器域名区分标示
//设置缓存key标示
NSString * const UserDefaultsClientServerKey = @"Client_Server_UserDefault";//使用业主端服务
NSString * const UserDefaultsBrowerServerKey = @"Brower_Server_UserDefault";//使用员工端服务

#pragma mark - Beta环境服务器地址
//设置缓存key标示
NSString * const UserDefaultsClientServerValue_beta = @"Client_Server_Beta_UserDefault";
NSString * const UserDefaultsBrowerServerValue_beta = @"Client_Brower_Beta_UserDefault";

#define kClient_beta  @"https://beta.uhomecp.com"
#define kImageClient_beta  @"https://betapic.uhomecp.com"
#define kSmallImageClient_beta  @"https://betapic.uhomecp.com/small"

//服务端
#define kBrower_beta  kClient_beta;
#define kImageBrower_beta  kImageClient_beta;
#define kSmallImageBrower_beta  kSmallImageClient_beta;

@implementation SEGServerManager

/**
 服务器地址拼接

 @author Sam
 @param value 服务器地址的值【服务器域名、服务器上下文、服务器url相对地址、特殊值(可忽略,eg:SPE=1001)】
 @return 完整的服务器地址
 */
+(NSString*)serverUrlJoint:(NSString*)value,...{
    va_list argumentList;
    va_start(argumentList, value);
    
    NSMutableString *stringM = [NSMutableString stringWithString:value];
    
    NSString *tmp = nil;
    while ((tmp = va_arg(argumentList, NSString *))) {
        [stringM appendString:tmp];
    }
    va_end(argumentList);
    
    return stringM;
}

/**
 业主端数据

 @param tag 1:接口请求地址，2:大图请求地址，3:小图请求地址
 @return 服务器域名
 */
+(NSString*)clientServer:(NSString *)tag{
    NSString * server = [[NSUserDefaults standardUserDefaults] objectForKey:UserDefaultsClientServerKey];

    if ([server isEqualToString:UserDefaultsClientServerValue_beta]) {
        if ([tag isEqualToString:@"1"]) return kClient_beta;
        if ([tag isEqualToString:@"2"]) return kImageClient_beta;
        if ([tag isEqualToString:@"3"]) return kSmallImageClient_beta;
    }

    return kClient_beta;
}


/**
 员工端数据
 
 @param tag 1:接口请求地址，2:大图请求地址，3:小图请求地址
 @return 服务器域名
 */
+(NSString*)browerServer:(NSString *)tag{
    NSString * server = [[NSUserDefaults standardUserDefaults] objectForKey:UserDefaultsBrowerServerKey];
    if ([server isEqualToString:UserDefaultsBrowerServerValue_beta]) {
        if ([tag isEqualToString:@"1"]) return kBrower_beta;
        if ([tag isEqualToString:@"2"]) return kImageBrower_beta;
        if ([tag isEqualToString:@"3"]) return kSmallImageBrower_beta;
    }

    return kBrower_beta;
}

/**
 获取客户端类型
 
 @return 2:iOS手机 3：iOS 平板 4：android 手机  5：android 平板
 */
+(NSString*)getClientSourceType{
    NSString *source = [[NSUserDefaults standardUserDefaults] objectForKey:UserDefaultsClientSourceTypeKey];
    if (!(source && source.length >0)) {
        [[NSUserDefaults standardUserDefaults] setObject:@"2" forKey:UserDefaultsClientSourceTypeKey];
        return @"2";
    }
    return source;
}

/**
 获取请求接口版本号
 
 @return NSString Value
 */
+(NSString*)getClientVersionCode{
    NSString *code = [[NSUserDefaults standardUserDefaults] objectForKey:UserDefaultsClientVersionCodeTypeKey];
    if (!(code && code.length >0)) {
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:UserDefaultsClientVersionCodeTypeKey];
        return @"1";
    }
    return code;
}
@end
